home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / XML Utilities / Professional Programmer XSL IDE / Xselerator25.msi / Data.Cab / F41236_sqrtSeq.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2002-02-06  |  3.8 KB  |  120 lines

  1. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  2. xmlns:xalan="http://xml.apache.org/xalan"
  3. xmlns:MyRepeatGenerator="MyRepeatGenerator" 
  4. xmlns:MyRepeatableFunction="MyRepeatableFunction"
  5. exclude-result-prefixes="xsl xalan MyRepeatGenerator MyRepeatableFunction"
  6. >
  7.  
  8.   <xsl:import href="take.xsl"/> 
  9.   
  10.   <!-- To be applied on any xml source -->
  11.   
  12.   <xsl:output indent="yes" omit-xml-declaration="yes"/>
  13.   
  14.   <MyRepeatGenerator:MyRepeatGenerator/>
  15.   <MyRepeatableFunction:MyRepeatableFunction/>
  16.   
  17.    <xsl:variable name="vMyRepeat" select="document('')/*/MyRepeatGenerator:*[1]"/>
  18.    <xsl:variable name="vMyFunction" select="document('')/*/MyRepeatableFunction:*[1]"/>
  19.   
  20.   <xsl:template match="/">
  21.      sqrt(9): 
  22.      <xsl:call-template name="sqrt">
  23.         <xsl:with-param name="takeElements" select="10"/>
  24.         <xsl:with-param name="N" select="9"/>
  25.      
  26.      </xsl:call-template>
  27.      
  28.      sqrt(16): 
  29.      <xsl:call-template name="sqrt">
  30.         <xsl:with-param name="takeElements" select="10"/>
  31.         <xsl:with-param name="N" select="16"/>
  32.      
  33.      </xsl:call-template>
  34.      sqrt(25): 
  35.      <xsl:call-template name="sqrt">
  36.         <xsl:with-param name="takeElements" select="10"/>
  37.         <xsl:with-param name="N" select="25"/>
  38.      
  39.      </xsl:call-template>
  40.      sqrt(36): 
  41.      <xsl:call-template name="sqrt">
  42.         <xsl:with-param name="takeElements" select="10"/>
  43.         <xsl:with-param name="N" select="36"/>
  44.      </xsl:call-template>
  45.      
  46.      sqrt(49): 
  47.      <xsl:call-template name="sqrt">
  48.         <xsl:with-param name="takeElements" select="10"/>
  49.         <xsl:with-param name="N" select="49"/>
  50.      </xsl:call-template>
  51.      
  52.      sqrt(64): 
  53.      <xsl:call-template name="sqrt">
  54.         <xsl:with-param name="takeElements" select="10"/>
  55.         <xsl:with-param name="N" select="64"/>
  56.      </xsl:call-template>
  57.      
  58.      sqrt(81): 
  59.      <xsl:call-template name="sqrt">
  60.         <xsl:with-param name="takeElements" select="10"/>
  61.         <xsl:with-param name="N" select="81"/>
  62.      </xsl:call-template>
  63.      
  64.      sqrt(100): 
  65.      <xsl:call-template name="sqrt">
  66.         <xsl:with-param name="takeElements" select="10"/>
  67.         <xsl:with-param name="N" select="100"/>
  68.      </xsl:call-template>
  69.      
  70.      sqrt(121): 
  71.      <xsl:call-template name="sqrt">
  72.         <xsl:with-param name="takeElements" select="10"/>
  73.         <xsl:with-param name="N" select="121"/>
  74.      
  75.      </xsl:call-template>
  76.   </xsl:template>
  77.   
  78.   <xsl:template name="sqrt">
  79.     <xsl:param name="takeElements"/>
  80.     <xsl:param name="N"/>
  81.     
  82.     <xsl:variable name="vrtfParams">
  83.       <param><xsl:value-of select="$N div 2"/></param>
  84.       <xsl:copy-of select="$vMyFunction"/>
  85.       <param><xsl:value-of select="$N"/></param>
  86.     </xsl:variable>
  87.  
  88.       <xsl:call-template name="take">
  89.         <xsl:with-param name="pN" select="$takeElements"/>
  90.         <xsl:with-param name="pGenerator" select="$vMyRepeat"/>
  91.         <xsl:with-param name="pParam0" select="xalan:nodeset($vrtfParams)/*"/>
  92.       </xsl:call-template>
  93.    
  94.   </xsl:template>
  95.  
  96.   <xsl:template name="myRepeater" match="*[namespace-uri()='MyRepeatGenerator']">
  97.      <xsl:param name="pList" select="/.."/>
  98.      <xsl:param name="pParams"/>
  99.      
  100.      <xsl:choose>
  101.          <xsl:when test="not($pList)">
  102.             <xsl:copy-of select="$pParams[1]/node()"/>
  103.          </xsl:when>
  104.          <xsl:otherwise>
  105.            <xsl:apply-templates select="$pParams[2]">
  106.              <xsl:with-param name="X" select="$pList[last()]"/>
  107.              <xsl:with-param name="N" select="$pParams[3]/node()"/>
  108.            </xsl:apply-templates>
  109.          </xsl:otherwise>
  110.      </xsl:choose>
  111.   </xsl:template>
  112.  
  113.   <xsl:template name="myRptFn" match="*[namespace-uri()='MyRepeatableFunction']">
  114.      <xsl:param name="X"/>
  115.      <xsl:param name="N"/>
  116.      
  117.      <xsl:value-of select="($X + ($N div $X)) div 2"/>
  118.   </xsl:template>
  119.  
  120. </xsl:stylesheet>